#!/usr/bin/env bash

source /usr/share/kwort/common/default

function show_default() {
	if [ -n "${2}" -a -e "/etc/sysconfig/net/${2}" ]; then
		source /etc/sysconfig/net/$2
		if [ -n "${!1}" ]; then
			echo "<default>${!1}</default>"
		fi
	fi
}

export MAIN_DIALOG="<window title=\"Kwort Network Manager\" icon-name=\"${KNM_IMG}\" window_position=\"1\" resizable=\"false\">
	<vbox>
		<frame Gateway Settings>
			<hbox>
				<pixmap>
					<input file>${GATEWAY_IMG}</input>
				</pixmap>
				<text>
					<label>Default Gateway: </label>
				</text>
				<entry>
					$(show_default GATEWAY gateway)
					<variable>GATEWAY</variable>
				</entry>
			</hbox>
		</frame>
		<hbox>
			<button cancel>
				<input file>${CANCEL_IMG}</input>
			</button>
			<button ok>
				<input file>${OK_IMG}</input>
			</button>
		</hbox>
	</vbox>
</window>"

eval $(gtkdialog --program=MAIN_DIALOG)

if [ "${EXIT}" == "Cancel" -o "${EXIT}" == "abort" -o -z "${HOSTNAME}" ]; then
	exit
fi

echo "GATEWAY=\"${GATEWAY}\"" > /etc/sysconfig/net/gateway
/etc/rc.d/rc.net restart gateway

